package com.love.poetry.interfaces;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.love.poetry.application.poetry.VerseService;
import com.love.poetry.domain.poetry.Verse;
import com.youboy.core.web.exception.ResourceNotFoundException;

@Controller
public class PoetryDetailController {
	
	@Autowired
	private VerseService verseService;
	
	@RequestMapping(value={"/poetry/{id}.html"},method=RequestMethod.GET)
	public String poetryDetail(@PathVariable("id")String id,Model model){
		Verse verse=verseService.get(id);
		if (null == verse) {
			throw new ResourceNotFoundException();
		}		
		model.addAttribute(verse);
		return "poetry_detail";
	}
}